Recursive locks know their current owner, and since we use the function
solely to determine whether a particular lock is being held by the
current CPU (which so far has been an imprecise check), make actually
check the owner for recusrively acquired locks.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Quan Xu <quan.xu@intel.com>
Acked-by: Tim Deegan <tim@xen.org>
int _spin_is_locked(spinlock_t *lock)
{
check_lock(&lock->debug);
- return lock->tickets.head != lock->tickets.tail;
+
+ /*
+ * Recursive locks may be locked by another CPU, yet we return
+ * "false" here, making this function suitable only for use in
+ * ASSERT()s and alike.
+ */
+ return lock->recurse_cpu == SPINLOCK_NO_CPU
+ ? lock->tickets.head != lock->tickets.tail
+ : lock->recurse_cpu == smp_processor_id();
}
int _spin_trylock(spinlock_t *lock)